package com.fudan.es.entity;

import org.apache.commons.text.StringEscapeUtils;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

public class QueryPack {

	private String field;
	private String operator;
	private String value;
	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	public String getOperator() {
		return operator;
	}
	public void setOperator(String operator) {
		this.operator = operator;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}

	public QueryBuilder query() {
		String operator = StringEscapeUtils.unescapeHtml4(this.operator);
		if("=".equals(operator)) {
			return QueryBuilders.queryStringQuery(this.field+":"+this.value);
		}else if(!"->".equals(operator)) {
			return QueryBuilders.queryStringQuery(this.field+":"+operator+this.value);
		}
		return QueryBuilders.queryStringQuery(this.field+":"+this.value);
	}
}
